/**
 * Created by fanshilei on 2015/10/10.
 */
jQuery.validator.addMethod("integer", function (value, element) {
    var tel = /^\d{1,9}$/;
    if (!tel.test(value)) {
        $(element).addClass("warnicon");
        showValidateTipsMsg("请输入有效正整数", $(element));
    } else {
        $(element).removeClass("warnicon");
        layer.closeAll('tips');
    }
    return true;
}, "");
jQuery.validator.addMethod("maxLength", function (value, element, params) {
    if (value.length > params[1]) {
        $(element).addClass("warnicon");
        showValidateTipsMsg("输入长度最大是" + params[1] + "的字符", $(element));
    } else {
        $(element).removeClass("warnicon");
        layer.closeAll('tips');
    }
    return true;
}, "");
jQuery.validator.addMethod("noBlank", function (value, element) {
    var tel = /^[^ ]*$/;
    if (!tel.test(value)) {
        $(element).addClass("warnicon");
        showValidateTipsMsg("不允许输入空格", $(element));
    } else {
        $(element).removeClass("warnicon");
        layer.closeAll('tips');
    }
    return true;
}, "");
jQuery.validator.addMethod("decimal", function (value, element, params) {
    var tel = eval("/^\\d{1," + params[0] + "}(?:\\.\\d{1," + params[1] + "})?$/");
    if (!tel.test(value)) {
        $(element).addClass("warnicon");
        showValidateTipsMsg("请输入有效数字,可精确到小数点后" + params[1] + "位", $(element));
    } else {
        $(element).removeClass("warnicon");
        layer.closeAll('tips');
    }
    return true;
}, "");
jQuery.validator.addMethod("fixLength", function (value, element, params) {
    var tel = eval("/^[\\S]{" + params[0] + "}$/");
    if (!tel.test(value)) {
        $(element).addClass("warnicon");
        showValidateTipsMsg("字符长度限制为" + params[1] + "个字符", $(element));
    } else {
        $(element).removeClass("warnicon");
        layer.closeAll('tips');
    }
    return true;
}, "");
jQuery.validator.addMethod("date", function (value, element) {
    var tel = /^((?:19|20)\d\d)-(0[1-9]|1[012])-(0[1-9]|[12][0-9]|3[01])$/;
    if (!tel.test(value)) {
        $(element).addClass("warnicon");
        showValidateTipsMsg("日期格式限制为YYYY-MM-DD", $(element));
    } else {
        $(element).removeClass("warnicon");
        layer.closeAll('tips');
    }
    return true;
}, "");
jQuery.validator.addMethod("myDecimal", function (value, element, params) {
    var myDecimal = eval("/^\\d{1," + (params[0] - params[1]) + "}(?:\\.\\d{1," + params[1] + "})?$/");
    if (!myDecimal.test(value)) {
        $(element).addClass("warnicon");
        showValidateTipsMsg("数字格式限制为最多" + (params[0] - params[1]) + "位整数,最多" + params[1] + "位小数", $(element));
    } else {
        $(element).removeClass("warnicon");
        layer.closeAll('tips');
    }
    return true;
}, "");
jQuery.validator.addMethod("isEmail", function (value, element) {
    var myReg = /^([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+@([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+\.[a-zA-Z]{2,3}$/;
    if (!myReg.test($(element).val())) {
        $(element).addClass("warnicon");
        showValidateTipsMsg("请输入有效的邮箱格式", $(element));
    } else {
        $(element).removeClass("warnicon");
        layer.closeAll('tips');
    }
    return true;
}, "");

